<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var arr = [1, 3, 5, 7, 9];


        // 两两交换
        function reverse(arr) {
            var len = arr.length;
            for (var i = 0; i < len / 2; i++) {
                // arr[i] 和 arr[len-i-1] 交换
                var temp = arr[i];
                arr[i] = arr[len - 1 - i];
                arr[len - 1 - i] = temp;
            }
        }
        reverse(arr);
        console.log(arr);

        var arr2 = [2, 4, 6, 8, 10];

        function reverse2(arr) {
            var tempArr = [];
            for (var i = 0; i < arr.length; i++) {
                tempArr.unshift(arr[i]);
            }
            return tempArr;
        }
        console.log(reverse2(arr2));
    </script>
</body>

</html>